package com.hlbspringcloud.graphqldemo.server;

import com.hlbspringcloud.graphqldemo.entity.User;
import com.hlbspringcloud.graphqldemo.service.UserService;
import graphql.kickstart.tools.GraphQLQueryResolver;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * TODO
 *
 * @author huangxiansheng
 * @date 2021/1/12 2:00 下午
 */
@Slf4j
@Component
public class QueryResolver implements GraphQLQueryResolver {

    @Autowired
    private UserService userService;

    public User user(String nickname){
        log.info("Query Resolver ==> user");
        log.info("params: nickname:{}", nickname);
        return userService.getUserByNickname(nickname);
    }

    public List<User> users() {
        log.info("Query Resolver ==> users");
        return userService.listUsers();
    }
}
